import 'dart:async';

import 'package:flutter/material.dart';
import 'package:x3_base_package/x3_base_package.dart';
import 'package:x3_business_core/business_common_template/models/business_detailed_order_service.dart';

/// author：william on 2021/3/17 20:48
/// email：362661044@qq.com
///
class BusinessDetailedOrderProvider {
  /// 服务集
  final BusinessDetailedOrderService service;

  /// 主单表单数据
  final BaseRequestFormProvider baseRequestFormProvider;

  /// 创建明细广播
  final StreamController<BusinessDetailedOrderTab> refreshTabStream;

  static BusinessDetailedOrderProvider of(context, {bool listen = true}) {
    return Provider.of<BusinessDetailedOrderProvider>(context, listen: listen);
  }

  /// 事件推送
  void refreshEmitter(BusinessDetailedOrderTab event) {
    this.refreshTabStream.sink.add(event);
  }

  /// 事件订阅
  void refreshSubscribe({@required String key, @required Function(BusinessDetailedOrderTab event) listen}) {
    this.refreshTabStream.stream.listen((event) {
      if (event.key.toString() == key) listen(event);
    });
  }

  BusinessDetailedOrderProvider({this.service, this.baseRequestFormProvider, this.refreshTabStream});
}

class BusinessDetailedOrderTab {
  final String key;
  final Map<String, dynamic> params;
  BusinessDetailedOrderTab({@required this.key, this.params = const {}});
}
